<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>测试页面</title>
    <link rel="stylesheet" type="text/css" href="../css/easyui/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../css/easyui/icon.css">
    <script src="../js/jquery/jquery.min.js"></script>
    <script src="../js/easyui/jquery.easyui.min.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
<h2>Custom DataGrid Pager</h2>
<a id="aid" href="javascript:void(0)" class="easyui-linkbutton" onclick="xiazai()">下载测试</a>
<table id="dg">
    <tr>
        <th><input id="tr1td1" value="11"></th>
        <th><input id="tr1td2" value="12"></th>
        <th><input id="tr1td3" value="13"></th>
        <th><input id="tr1td4" value="14"></th>
    </tr>
    <tr>
        <td><input id="tr2td1" value="21"></td>
        <td><input id="tr2td2" value="22"></td>
        <td><input id="tr2td3" value="23"></td>
        <td><input id="tr2td4" value="24"></td>
    </tr>
    <tr>
        <td><input id="tr3td1" value="31"></td>
        <td><input id="tr3td2" value="32"></td>
        <td><input id="tr3td3" value="33"></td>
        <td><input id="tr3td4" value="34"></td>
    </tr>
</table>
<div>
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="tpfcs()">通配符测试</a>
</div>
<script>
    $(function () {
    });
    function tpfcs() {
        var key = 'td1';
        var a = $("#dg input[id*="+key+"]");
        console.log(a);
    }
    function xiazai() {
        $.ajax({
            url: "/customer/downloadBlob", async: true, data:{"id":1}, success: function (data) {
                console.log(data);

                var blob = data;
                // FileReader主要用于将文件内容读入内存
                var reader = new FileReader();
                reader.readAsDataURL(blob);
                // onload当读取操作成功完成时调用
                reader.onload = function(e) {
                    var a = document.createElement('a');
                    // 获取文件名fileName
                    var fileName = "文件名称.jpg";
                    fileName = fileName[fileName.length - 1];
                    fileName = fileName.replace(/"/g, "");
                    a.download = fileName;
                    a.href = e.target.result;
                    document.body.appendChild(a);
                    a.click();
                    document.body.removeChild(a);
                }

                // var fileName = "文件名称";
                // var base64Data = data;
                // var data = base64Data.split(','),
                //     mime = data[0].match(/:(.*?);/)[1],
                //     byteString = atob(data[1]),
                //     byteLength  = byteString .length,
                //     uInt8Array = new Uint8Array(byteLength);
                // while(n--){
                //     uInt8Array [n] = byteString .charCodeAt(n);
                // }
                // var file = new File([uInt8Array], fileName, {type:mime});


                alert("二维码下载成功！path="+data);
            }
        });

        //通过函数将base64转化为文件对象
        function convertBase64UrlToFile(base64) {

        }
    }

</script>
</body>
</html>